package jvm.jtacck.db.records;

import java.util.Collections;
import java.util.List;

/**
 * 
 * @author Chris Gamble
 * 
 *         Represents a Client_Site in our database. A Client Site is a sub
 *         section of a hospital from where specimens can be picked up for
 *         shipping. Client sites have the fields client_id, name, the
 *         hospital_id of the hospital it belongs to and instructions. The
 *         instructions are for the courier to know what where to pick up the
 *         specimens from the site.
 * 
 */
public class ClientSite extends Record {
    private static final long serialVersionUID = 4834310666833409829L;
    public final int client_id;
    public final String name;
    public final Hospital hospital;
    public final List<String> instructions;
    public final String phone_number;

    /**
     * Constructs a new ClientSite Record
     * 
     * @param id
     *            the id number of the clientsite
     *            NON-NULLABLE
     * @param name
     *            the name of the clientsite
     * @param hosp
     *            the id of the hospital to which this site belongs
     *            NON-NULLABLE
     * @param instructs
     *            A Sequential List of Instructions for couriers who pick up at
     *            this ClientSite
     * @param phone
     *            10 digit phone number of the ClientSite
     */
    public ClientSite(int id, String name, Hospital hosp, List<String> instructs, 
                        String phone) {
        this.client_id = id;
        this.name = name;
        this.hospital = hosp;
        this.instructions = Collections.unmodifiableList(instructs);
        this.phone_number = phone;
    }
    
    @Override
    public boolean equals(Object o){
        if (o instanceof ClientSite) {
            ClientSite other = (ClientSite) o;
            
            boolean x = 
                   client_id == other.client_id &&
                   checkString(name, other.name) &&
                   checkString(phone_number, other.phone_number) &&
                   checkList(instructions, other.instructions) &&
                   hospital.equals(other.hospital);
            return x;
        }
        return false;
    }
    
    public boolean checkString(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        }else {
            return s1.equals(s2);
        }
    }
    
    public boolean checkList(List<String> l1, List<String> l2) {
        if (l1 == null) {
            return l2 == null;
        }else {
            return l1.equals(l2);
        }
    }
    
    @Override
    public int hashCode() {
        return client_id + name.hashCode() + 
        hospital.hashCode() + phone_number.hashCode();
    }
    
    public String toString() {
        return client_id + ": " + name + ", " +  hospital.name + ", " + phone_number + ".";
    }
}
